package com.mdx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mdx.bean.GalleryBean;
import com.mdx.bean.LogBean;
import com.mdx.bean.UserBean;

import com.mdx.dao.UserDao;
import com.mdx.service.IUserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
@Transactional
public class UserServiceImpl extends ServiceImpl<UserDao,UserBean> implements IUserService {

    @Override
    public void updateById(int userId, String pwd, String power) {
        UserBean userBean = this.getById(userId);
        userBean.setPwd(pwd);
        userBean.setPower(power);
        this.updateById(userBean);
    }

    @Override
    public IPage<UserBean> findByUserType(int pageNO, int pageSize, String power) {
        IPage<UserBean> page = new Page<>(pageNO,pageSize);
        QueryWrapper wrapper = new QueryWrapper();
        if (power =="所有用户"){
            return this.page(page);
        }else {
            wrapper.eq("f_power",power);
        }
        IPage<UserBean> iPage = this.page(page,wrapper);
        return iPage;
    }

    @Override
    public UserBean login(String username, String pwd) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("f_username", username);
        wrapper.eq("f_pwd", pwd);
        return this.getOne(wrapper);
    }
}
